package week8;

/**
 * PrioritizedObject represents a node in a priority queue containing a
 * comparable object, arrival order, and a priority value.
 * 
 * @author Lewis and Chase
 * @version 4.0
 */
public class PrioritizedObject<T> implements Comparable<PrioritizedObject>
{
    private static int nextOrder = 0;
    private int priority;
    private int arrivalOrder;
    private T element;


    public PrioritizedObject(T element, int priority) 
    {
        this.element = element;
        this.priority = priority;
        arrivalOrder = nextOrder;
        nextOrder++;
    }
    
    // 返回元素
    public T getElement() 
    {
        return element;
    }
    
    // 返回优先级
    public int getPriority() 
    {
        return priority;
    }

    // 返回该节点的到达顺序。
    public int getArrivalOrder() 
    {
        return arrivalOrder;
    }
    
    // 返回此节点的字符串表示形式。
    public String toString() 
    {
        return (element + "  " + priority + "  " + arrivalOrder);
    }

    public int compareTo(PrioritizedObject obj)
    {
      int result;
				
      if (priority > obj.getPriority())
          result = 1;
      else if (priority < obj.getPriority())
          result = -1;
      else if (arrivalOrder > obj.getArrivalOrder())
          result = 1;
      else
          result = -1;
      
      return result;
    }
}


